//
//  SetUserInformationViewController.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/20.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "SetUserInformationViewController.h"
#import "LoginViewController.h"
#import "PersonInformationViewController.h"
#import "CountManagerViewController.h"
#import "ScoreViewController.h"
@interface SetUserInformationViewController ()<UIScrollViewDelegate>

//五个button下面的view
@property (strong, nonatomic) IBOutlet UIView *UserView;

//退出按钮
@property (strong, nonatomic) IBOutlet UIButton *cancelButton;
@property (strong, nonatomic) IBOutlet UIButton *cancelCacheButton;


@end

@implementation SetUserInformationViewController

//点击用户实现的方法
- (IBAction)UserInforMation:(id)sender {
    
    PersonInformationViewController *personVC = [[PersonInformationViewController alloc] init];
    [self.navigationController pushViewController:personVC animated:YES];
}

//点击账号管理实现的方法
- (IBAction)CountManager:(id)sender {
    CountManagerViewController *countVC = [[CountManagerViewController alloc] init];
    [self.navigationController pushViewController:countVC animated:YES];
}

//点击积分管理实现的方法
- (IBAction)Score:(id)sender {
    ScoreViewController *scoreVC = [[ScoreViewController alloc] init];
    [self.navigationController pushViewController:scoreVC animated:YES];
}


- (void) getSizeCache{
    CGFloat size = [SDImageCache sharedImageCache].getSize / 1000.0 /1000;
    [self.cancelCacheButton setTitle:[NSString stringWithFormat:@"    缓存大小为：%.2fMB", size] forState:UIControlStateNormal];
}
//点击清除缓存实现的方法
- (IBAction)cancelCache:(id)sender {
    [[SDImageCache sharedImageCache] clearDisk];
    [self.cancelCacheButton setTitle:@"    缓存大小为：0.00MB" forState:UIControlStateNormal];
}


//点击退出实现的方法
- (IBAction)cancelLogin:(id)sender {
    if (![[userManager getUsrID] isEqualToString:@" "] ) {
        
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"田园生活" message:@"退出当前应用" preferredStyle:UIAlertControllerStyleAlert];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [alertVC dismissViewControllerAnimated:YES completion:nil];
        }]];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            //当有用户的信息时删除用户ID， 退到登陆界面
            [userManager cancelUserID];
//            [userManager cancelUserName];
//            [userManager cancelUserHeadImage];
            LoginViewController *loginVC = [[LoginViewController alloc] init];
            [self presentViewController:loginVC animated:YES completion:nil];
        }]];
        [self presentViewController:alertVC animated:YES completion:nil];
    }
}




- (void)viewDidLoad {
    [super viewDidLoad];
    [self getSizeCache];//获得缓存大小
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"设置";
    self.navigationController.navigationBar.translucent = NO;

    self.UserView.layer.cornerRadius = 5;
    self.UserView.layer.borderWidth = 1;
    self.cancelButton.layer.cornerRadius = 5;
    self.cancelButton.layer.borderWidth = 1;
    
    // Do any additional setup after loading the view from its nib.
}



//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    NSLog(@"1111");
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
